﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.Sql;
using System.Data.SqlClient;
using System.Data.SqlTypes;
using System.Data;
using RedemptoristRetreatCenter.DatabaseUtility;

namespace RedemptoristRetreatCenter
{
    /// <summary>
    /// Allows user to view a list of active staff members
    /// </summary>
    public partial class ViewStaff : System.Web.UI.Page
    {
        /// <summary>
        /// On page load, create/populate the table for the gridview with staff info
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void Page_Load(object sender, EventArgs e)
        {
            DataTable staffTable = new DataTable();
            DataRow tableRow = null;
            Boolean isAdmin;
            UserAccountUtility userUtil = new UserAccountUtility();
            List<UserAccountInfo> userInfoList = userUtil.getStaffList();

            // -- create staff table --
            staffTable.Columns.Add(new DataColumn("First Name", typeof(string)));
            staffTable.Columns.Add(new DataColumn("Last Name", typeof(string)));
            staffTable.Columns.Add(new DataColumn("Business Phone", typeof(string)));

            // -- populate staff table with staff info --
            foreach (UserAccountInfo userInfo in userInfoList)
            {
                tableRow = staffTable.NewRow();
                tableRow["First Name"] = userInfo.firstName;
                tableRow["Last Name"] = userInfo.lastName;
                tableRow["Business Phone"] = userInfo.businessPhone;

                staffTable.Rows.Add(tableRow);
            }

            ViewState["CurrentTable"] = staffTable;

            StaffGridView.DataSource = staffTable;
            StaffGridView.DataBind();

            if (Session["isAdmin"] == null)
                isAdmin = false;
            else
                isAdmin = (Boolean)Session["isAdmin"];
            
            // -- changing visibility of add staff member button based on whether or not the user is an administrator --
            if (isAdmin)
                addStaffMember.Visible = true;
            else
                addStaffMember.Visible = false;
        }

        /// <summary>
        /// Upon clicking the addStaff button, redirect the user to the Add Staff page 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        protected void addStaff_Click(object sender, EventArgs e)
        {
            Response.Redirect("AddStaff.aspx");
        }
    }
}